package com.java复习.反射;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

public class Demo2 {
    public static void main(String[] args) throws DocumentException {
        // 解析xml文件
        SAXReader saxReader = new SAXReader();

        Document document = saxReader.read("resources\\demo1.xml");

        // 获取根元素
        Element rootElement = document.getRootElement();

        // 通过根元素，来获取子元素的集合
        List<Element> beanList = rootElement.elements("bean");

        for (Element element:beanList){
            String id = element.attributeValue("id");
            String className = element.attributeValue("className");
            System.out.println("bean属性"+id+","+className);

            List<Element> proList = element.elements("property");
            for (Element property:proList){
                String name = property.attributeValue("name");
                String value = property.attributeValue("value");
                System.out.println("property属性：name"+name+"value"+value);
            }
        }

        System.out.println();

    }
}
